package com.yoga.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yoga.model.Reservation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author yan
 * @date 2025/8/17
 */
@Mapper
public interface ReservationMapper {
     Page<Reservation> findAll(Page<Reservation> page, Reservation reservation);

    int deleteByIds(Integer[] ids);

    int insert(Reservation reservation);

    int updateById(Reservation reservation);

    @Select("SELECT COUNT(*) FROM reservation WHERE DATE(reserve_time) = CURDATE()")
    int countToday();

    @Select("SELECT DATE(reserve_time) as date, COUNT(*) as count " +
            "FROM reservation WHERE reserve_time >= DATE_SUB(CURDATE(), INTERVAL 6 DAY) " +
            "GROUP BY DATE(reserve_time) ORDER BY DATE(reserve_time)")
    List<Map<String, Object>> getLast7DaysTrend();


    @Update("UPDATE reservation SET status = #{status} WHERE course_id = #{courseId} AND status = 0")
    int updateStatusByCourseId(@Param("courseId") Integer courseId, @Param("status") Integer status);
}
